package com.fdd.spring.aop.proxy;

import java.util.Arrays;

public class MyProxyProvider {
    private SmartAnimalable target_obj;
    public MyProxyProvider(SmartAnimalable target_obj) {
        this.target_obj = target_obj;
    }


    public SmartAnimalable getProxy() {
        SmartAnimalable proxy = (SmartAnimalable) java.lang.reflect.Proxy.newProxyInstance(
                target_obj.getClass().getClassLoader(),
                target_obj.getClass().getInterfaces(),
                (proxy1, method, args) -> {
                    System.out.println("MyProxyProvider 开始" + method.getName() + "方法，参数：" + Arrays.asList(args));
                    Object result = method.invoke(target_obj, args);
                    System.out.println("正常结束，返回值：" + result);
                    System.out.println("MyProxyProvider 结束" + method.getName() + "方法，参数：" + Arrays.asList(args));
                    return result;
                }
        );
        return proxy;
    }
}
